#!/usr/bin/env bash

#安装JDK1.8

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install lnmp"
    exit 1
fi


cur_dir=$(pwd)
packages_dir="/home/soft/"
packagesName="jdk-8u11-linux-x64.tar.gz"
sysPath="/usr/local/"

Init_Main(){

    #创建文件夹
    mkdir /usr/local/java/
    #查看安装程序
    echo "[-] Yum remove packages..."
    rpm -qa | grep -i jdk

    rpm -e ${packagesName} --nodeps

}


Init_Install(){
    Init_Main
    #解压安装包
    echo "tar -zxvf jdk-8u11-linux-x64.tar.gz -C /usr/local/java/"
    tar -zxvf jdk-8u11-linux-x64.tar.gz -C /usr/local/java/

    #配置环境变量
    conf_JAVA

    test_JAVA

}



conf_JAVA(){
    echo "cat /etc/profile"
     cat >>/etc/profile<<"EOF"


export JAVA_HOME=/usr/local/java/jdk1.8.0_11
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tool.jar
EOF


echo "source /etc/profile"
source /etc/profile


}


#测试java
test_JAVA(){
    echo java -version
}


Init_Install

exit
